package com.dk.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dk.pojo.Users;
import com.dk.mapper.UsersMapper;
import com.dk.service.IUsersService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.catalina.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author author
 * @since 2022-07-08
 */
@Service
public class UsersServiceImpl extends ServiceImpl<UsersMapper, Users> implements IUsersService {

    @Autowired
    private UsersMapper usersMapper;
    @Override
    public List<Users> login(String username, String password) {
        QueryWrapper<Users> queryWrapper=new QueryWrapper<>();
        queryWrapper.eq("username",username);
        queryWrapper.eq("password",password);

        return usersMapper.selectList(queryWrapper);
    }

    @Override
    public IPage<Users> getUserList(Page<Users> usersIPage, Users users) {
        QueryWrapper<Users> wrapper=new QueryWrapper<>();

        if (!StringUtils.isEmpty(users.getName())){
            wrapper.like("name",users.getName());
        }
        if (!StringUtils.isEmpty(users.getUsername())){
            wrapper.eq("username",users.getUsername());
        }
        if (!StringUtils.isEmpty(users.getStat())){
            wrapper.eq("stat",users.getStat());
        }
        if (users.getMaketime()!=null){
            wrapper.eq("maketime",users.getMaketime());
        }
//        usersMapper.select
        return usersMapper.selectPage(usersIPage,wrapper);
    }

    @Override
    public List<Users> getUsersList(Users users) {
        QueryWrapper<Users> wrapper=new QueryWrapper<>();

        if (!StringUtils.isEmpty(users.getName())){
            wrapper.eq("name",users.getEmil());
        }
        if (!StringUtils.isEmpty(users.getUsername())){
            wrapper.eq("username",users.getUsername());
        }
        if (!StringUtils.isEmpty(users.getStat())){
            wrapper.eq("stat",users.getStat());
        }
        return usersMapper.selectList(wrapper);
    }
}
